using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VOL.Entity.DomainModels;
using SqlSugar;

namespace VOL.demo.Repositories
{
    public partial class Sys_DepartmentRepository
    {
        /// <summary>
        /// 获取部门下拉选项
        /// </summary>
        /// <returns>部门列表</returns>
        public async Task<List<Sys_Department>> GetDepartmentOptionsAsync()
        {
            return await DbContext.Queryable<Sys_Department>()
                .Where(x => x.Enable == 1)
                .OrderBy(x => x.DepartmentName)
                .ToListAsync();
        }

        /// <summary>
        /// 根据部门ID获取部门信息
        /// </summary>
        /// <param name="departmentId">部门ID</param>
        /// <returns>部门信息</returns>
        public async Task<Sys_Department> GetDepartmentByIdAsync(string departmentId)
        {
            if (Guid.TryParse(departmentId, out Guid guidId))
            {
                return await DbContext.Queryable<Sys_Department>()
                    .Where(x => x.DepartmentId == guidId && x.Enable == 1)
                    .FirstAsync();
            }
            return null;
        }
    }
}
